public class Solution29 {
    /**
     * 两数相除
     */
    public int divide(int dividend, int divisor) {
        long dividend1 = dividend;
        boolean flag = false;
        if (dividend1 == 0) return 0;
        if (dividend1 < 0) {
            flag = true;
            dividend1 = -dividend1;
        }
        if (divisor < 0) {
            flag = !flag;
            divisor = -divisor;
        }
        long div = 0;
        long add = divisor;
        while (add <= dividend1) {
            add += divisor;
            div++;
        }
        if (div > Integer.MAX_VALUE) return Integer.MAX_VALUE;
        return (int) (flag ? -div : div);
    }
}
